package com.example.demo.controller;

import com.example.demo.dto.StudentDto;
import com.example.demo.dto.StudentQueryCriteria;
import com.example.demo.service.StudentService;
import com.example.demo.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "学生管理")
@Slf4j
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @ApiOperation("学生列表")
    @PostMapping("/list")
    @PreAuthorize("@el.check('student:list')")
    public ResponseEntity<Object> getStudents(StudentQueryCriteria criteria){
        List<StudentDto> stuList = studentService.findAll(criteria);
        return new ResponseEntity<>(ResultUtils.ok("查询成功").put("studentList",stuList), HttpStatus.OK);
    }
}
